package com.aomiao.orderserver.service.impl;

import com.aomiao.orderserver.entity.Order;
import com.aomiao.orderserver.feign.MessageFeignClient;
import com.aomiao.orderserver.feign.ProductFeignClient;
import com.aomiao.orderserver.mapper.OrderMappper;
import com.aomiao.orderserver.service.OrderService;
import com.codingapi.tx.annotation.TxTransaction;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.jms.Destination;
import javax.transaction.Transactional;
import java.util.List;

/**
 * @author xiah
 * @date 2018/5/11 18:36
 */
@Service
public class OrderServiceImpl implements OrderService {
       @Resource
       private JmsMessagingTemplate jmsMessagingTemplate;

       @Autowired
       private OrderMappper orderMappper;

       @Autowired
       private MessageFeignClient messageFeignClient;

       @Autowired
       private ProductFeignClient productFeignClient;

       @Override
       public void testActiveMqp() {
              Destination dd = new ActiveMQQueue("first.blood");
              jmsMessagingTemplate.convertAndSend(dd, "111");
       }

       @Override
       public List<Order> getOrderList() {
              Order oo = orderMappper.getOne(1L);
              Order ss = orderMappper.findOne(1L);
              List<Order> list = orderMappper.findAll();
              return list;
       }

       @Override
       @TxTransaction(isStart = true)
       @Transactional
       public Long addMessage() {
              productFeignClient.addProduct();
              return messageFeignClient.addMessage();
       }
}
